package com.lb.sentinelproject.exception;

import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowException;
import com.lb.sentinelproject.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 功能描述: 异常处理类<br>
 * @Author: Edward
 * @Date: 2020/12/24 13:59
 */
@Slf4j
@Component
@RestControllerAdvice
@Order(Ordered.HIGHEST_PRECEDENCE)
public class GlobalExceptionHandler {

    /**
     * 功能描述: 处理ParamFlowException<br>
     * @param ex
     * @return: {@link R}
     * @Author: Edward
     * @Date: 2021/1/20 10:13
     */
    @ExceptionHandler(value = ParamFlowException.class)
    protected R handleParamFlowException(ParamFlowException ex) {
        //获取所有错误信息
        return R.error(4000,"热点参数限流了");
    }
}
